package com.ttg.utils.connection.handler;


import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.ResponseHandler;
import org.apache.http.util.EntityUtils;

import java.io.IOException;
import java.nio.charset.Charset;

public class BaseHttpResponseHandler implements ResponseHandler<BaseHttpResponse> {

    public BaseHttpResponse handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
        HttpEntity entity = null;

        BaseHttpResponse var6;
        try {
            entity = ResponseHandlerHelper.handleNon2xxStatus(response);
            Charset responseCharset = ResponseHandlerHelper.getResponseCharset(entity);
            byte[] exceptionInfo = ResponseHandlerHelper.handleCustomExceptionStatus(response);
            BaseHttpResponse parameters = null;
            if(exceptionInfo != null) {
                parameters = new BaseHttpResponse(responseCharset);
                parameters.setBizParameters(exceptionInfo);
                var6 = parameters;
                return var6;
            }

            parameters = ResponseHandlerHelper.getParameters(entity, responseCharset);
            var6 = parameters;
        } finally {
            EntityUtils.consume(entity);
        }

        return var6;
    }
}
